<script lang="ts" setup name="Warehouse">
import { CirclePlus, Delete, EditPen, FolderDelete } from '@element-plus/icons-vue'
import { ProTableInstance } from '~/library/components/ProTable/interface'
import { Procure } from '~/src/api/interface/procure'
import { deleteWareHouseAPI, getRejectionListAPI, unCheckWareHouseAPI } from '~/src/api/procure'
import { columns } from './info/columns'

const initParams = reactive({ timeType: 2, orderType: 1 })
const router = useRouter()

const goDetail = (data: any) => {
  if (data) {
    // 判断状态是是什么查看还是编辑
    router.push('/procure/warehouseEdit?type=' + (data.checkFlag ? 'view' : 'edit') + '&orderNo=' + data.id)
  } else {
    router.push('/procure/warehouseEdit?type=add')
  }
}

const tableRef = ref<ProTableInstance>()
// 删除
const onDeleteRow = async (params: Procure.Warehouse) => {
  await useHandleData(deleteWareHouseAPI, { id: params.id }, `删除编号【${params.orderNo}】收货单`)
  tableRef.value?.getTableList()
}

const onCancelRow = async (params: Procure.Warehouse) => {
  await useHandleData(unCheckWareHouseAPI, { id: params.id }, `反审核编号【${params.orderNo}】收货单`)
  tableRef.value?.getTableList()
}
</script>

<template>
  <div class="auto-height-container main-box">
    <pro-table
      ref="tableRef"
      :columns="columns"
      :indent="20"
      :initParam="initParams"
      :isCard="false"
      :request-api="getRejectionListAPI"
      row-key="id"
      title="收货单列表"
    >
      <template #tableHeader>
        <el-button :icon="CirclePlus" type="primary" @click="goDetail('')">新增收货单</el-button>
        <el-button :icon="Delete">删除</el-button>
      </template>
      <template #date="{ row }">
        {{ row.date ? row.date.slice(0, 11) : '' }}
      </template>
      <template #orderNo="{ row }">
        <el-button :icon="EditPen" link type="primary" @click="goDetail(row)">{{ row.orderNo }}</el-button>
      </template>
      <template #operation="scope">
        <el-button v-if="!scope.row.checkFlag" v-auth="'delete'" :icon="FolderDelete" link type="primary" @click="onDeleteRow(scope.row)">
          删除
        </el-button>

        <el-button v-if="scope.row.checkFlag" v-auth="'cancel'" :icon="Delete" link type="primary" @click="onCancelRow(scope.row)">
          反审核
        </el-button>
      </template>
    </pro-table>
  </div>
</template>

<style lang="scss" scoped></style>
